package cn.explink.dop.entity.vo;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.codehaus.jackson.annotate.JsonIgnore;
import org.hibernate.annotations.GenericGenerator;

import cn.explink.distributor.framework.CommonTarget;
import cn.explink.dop.enums.DeliveryManEnum;
import cn.explink.dop.enums.DeliveryManStatusEnum;
import cn.explink.dop.enums.pub.YesNoEnum;
import cn.explink.eap.web.system.pojo.base.TSUser;

/**
 *
 * @author firefly 2015-2-28 10:28
 *
 */
@Entity
@Table(name = "bd_deliveryman")
public class DeliveryManVO extends CommonTarget implements java.io.Serializable {

	private static final long serialVersionUID = 1465844322029884081L;

	private String id;

	/** 人员名称 */
	private String delName;
	/**
	 * 配送员状态
	 */
	private int status;

	private String coordinate;

	/**
	 * 是否有POS机
	 */
	private int havingPOS;

	/**
	 * 是否有保温箱
	 */
	private int havingWarmBox;

	/** 送餐人员证件编号 */
	private String delCertificates;
	/** 送餐人员照片路径 */
	private String delPortrait;
	/** 送餐人员电话 */
	private String delTelephone;
	/** 送餐人员简介 */
	private String delIntroduction;
	/** 每日送餐最大量 */
	private int delMaxmum;
	/** 是否启用 */
	private int delEnabled;
	/** 对应用户 */
	private TSUser sUser;

	private List<AreaVO> areaList;

	private List<StorefrontVO> storefrontList;
	/**
	 * 关联所属配送公司
	 */
	private DeliveryCompanyVO deliveryCompany;
	/**
	 * 配送员类型，1：属于配送公司，2：属性商户，3：属性门店，4：属于总部
	 */
	private int type;
	/**
	 * 是否是配送员，1：是，2：否，
	 */
	private int isDeliveryMan;
	/**
	 * 订单来源
	 */
	private String orderSource;
	/**
	 * postman表中的id
	 */
	private Integer postmanid;
	

	/*private PostmanVO postman;
	
	@OneToOne
	@JoinColumn(name="postmanId")
	public PostmanVO getPostman() {
		return postman;
	}

	public void setPostman(PostmanVO postman) {
		this.postman = postman;
	}*/


	@Id
	@GeneratedValue(generator = "paymentableGenerator")
	@GenericGenerator(name = "paymentableGenerator", strategy = "uuid")
	@Column(name = "ID", nullable = false, length = 32)
	public String getId() {
		return this.id;
	}

	public void setId(String id) {
		this.id = id;
	}
	
	@Column(name = "postman_id")
	public Integer getPostmanid() {
		return postmanid;
	}

	public void setPostmanid(Integer postmanid) {
		this.postmanid = postmanid;
	}
	
	@Column(name = "del_name", nullable = true, length = 100)
	public String getDelName() {
		return this.delName;
	}

	public void setDelName(String delName) {
		this.delName = delName;
	}

	public int getStatus() {
		return this.status;
	}

	@Transient
	public String getStatusText() {
		return DeliveryManStatusEnum.getTextByValue(this.status);
	}

	public void setStatus(int status) {
		this.status = status;
	}

	public String getCoordinate() {
		return this.coordinate;
	}

	public void setCoordinate(String coordinate) {
		this.coordinate = coordinate;
	}

	@Column(name = "having_pos")
	public int getHavingPOS() {
		return this.havingPOS;
	}

	public void setHavingPOS(int havingPOS) {
		this.havingPOS = havingPOS;
	}

	@Column(name = "having_warm_box")
	public int getHavingWarmBox() {
		return this.havingWarmBox;
	}

	public void setHavingWarmBox(int havingWarmBox) {
		this.havingWarmBox = havingWarmBox;
	}

	@Column(name = "del_certificates", nullable = true, length = 100)
	public String getDelCertificates() {
		return this.delCertificates;
	}

	public void setDelCertificates(String delCertificates) {
		this.delCertificates = delCertificates;
	}

	@Column(name = "del_portrait", nullable = true, length = 200)
	public String getDelPortrait() {
		return this.delPortrait;
	}

	public void setDelPortrait(String delPortrait) {
		this.delPortrait = delPortrait;
	}

	@Column(name = "del_telephone", nullable = true, length = 20)
	public String getDelTelephone() {
		return this.delTelephone;
	}

	public void setDelTelephone(String delTelephone) {
		this.delTelephone = delTelephone;
	}

	@Column(name = "del_introduction", nullable = true, length = 500)
	public String getDelIntroduction() {
		return this.delIntroduction;
	}

	public void setDelIntroduction(String delIntroduction) {
		this.delIntroduction = delIntroduction;
	}

	@Column(name = "del_maxmum", nullable = true, length = 5)
	public int getDelMaxmum() {
		return this.delMaxmum;
	}

	public void setDelMaxmum(int delMaxmum) {
		this.delMaxmum = delMaxmum;
	}

	@Column(name = "del_enabled", nullable = true, length = 2)
	public int getDelEnabled() {
		return this.delEnabled;
	}

	public void setDelEnabled(int delEnabled) {
		this.delEnabled = delEnabled;
	}
	
	@Column(name = "is_DeliveryMan")
	public int getIsDeliveryMan() {
		return this.isDeliveryMan;
	}

	@Transient
	public String getIsDeliveryManText() {
		return YesNoEnum.getTextByValue(this.isDeliveryMan);
	}

	public void setIsDeliveryMan(int isDeliveryMan) {
		this.isDeliveryMan = isDeliveryMan;
	}

	@Column(name = "order_Source")
	public String getOrderSource() {
		return this.orderSource;
	}

	public void setOrderSource(String orderSource) {
		this.orderSource = orderSource;
	}

	@JsonIgnore
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "s_user")
	public TSUser getsUser() {
		return this.sUser;
	}

	public void setsUser(TSUser sUser) {
		this.sUser = sUser;
	}

	@Transient
	public String getsUserName() {
		try {
			return this.getsUser().getRealName();
		} catch (Exception e) {
			// TODO: handle exception
			return "";
		}
	}

	@Transient
	public String getUserId() {
		try {
			return this.getsUser().getId();
		} catch (Exception e) {
			// TODO: handle exception
			return "";
		}
	}

	@Transient
	public String getLoginUserName() {
		try {
			return this.getsUser().getUserName();
		} catch (Exception e) {
			// TODO: handle exception
			return "";
		}
	}

	@JsonIgnore
	@ManyToMany(targetEntity = AreaVO.class, cascade = CascadeType.ALL)
	@JoinTable(name = "bd_area_deliveryman", joinColumns = @JoinColumn(name = "deliveryman_id"), inverseJoinColumns = @JoinColumn(name = "area_id"))
	public List<AreaVO> getAreaList() {
		return this.areaList;
	}

	public void setAreaList(List<AreaVO> areaList) {
		this.areaList = areaList;
	}

	@Transient
	public List<String> getAreaIdList() {
		List<String> areaIdList = new ArrayList<String>();
		if ((this.areaList != null) && (this.areaList.size() > 0)) {
			for (AreaVO areaVO : this.areaList) {
				areaIdList.add(areaVO.getId());
			}
		}
		return areaIdList;
	}

	@Transient
	public String getAreaId() {
		String areaId = "";
		if ((this.areaList != null) && (this.areaList.size() > 0)) {
			for (AreaVO areaVO : this.areaList) {
				areaId += areaVO.getId();
			}
		}
		return areaId;
	}

	@Transient
	public String getAreaName() {
		String areaName = "";
		if ((this.areaList != null) && (this.areaList.size() > 0)) {
			for (AreaVO areaVO : this.areaList) {
				areaName += " " + areaVO.getBaseAreaName();
			}
		}
		return areaName;
	}

	@JsonIgnore
	@ManyToMany(targetEntity = StorefrontVO.class, cascade = CascadeType.ALL)
	@JoinTable(name = "bd_deliveryman_storefront", joinColumns = @JoinColumn(name = "deliveryman_id"), inverseJoinColumns = @JoinColumn(name = "storefront_id"))
	public List<StorefrontVO> getStorefrontList() {
		return this.storefrontList;
	}

	@JsonIgnore
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "Company_Id")
	public DeliveryCompanyVO getDeliveryCompany() {
		return this.deliveryCompany;
	}

	public void setDeliveryCompany(DeliveryCompanyVO deliveryCompany) {
		this.deliveryCompany = deliveryCompany;
	}

	@Column(columnDefinition = "int default 1")
	public int getType() {
		return this.type;
	}

	public void setType(int type) {
		this.type = type;
	}
	
	
	@Transient
	public List<String> getStorefrontIdList() {
		List<String> storefrontIdList = new ArrayList<String>();
		if ((this.storefrontList != null) && (this.storefrontList.size() > 0)) {
			for (StorefrontVO storefrontVO : this.storefrontList) {
				storefrontIdList.add(storefrontVO.getId());
			}
		}
		return storefrontIdList;
	}

	public void setStorefrontList(List<StorefrontVO> storefrontList) {
		this.storefrontList = storefrontList;
	}

	@Transient
	public String getStorefrontId() {
		String storefrontId = "";
		if ((this.storefrontList != null) && (this.storefrontList.size() > 0)) {
			for (StorefrontVO storefrontVO : this.storefrontList) {
				storefrontId += storefrontVO.getId();
			}
		}
		return storefrontId;
	}

	@Transient
	public String getStorefrontName() {
		String storefrontName = "";
		if ((this.storefrontList != null) && (this.storefrontList.size() > 0)) {
			for (StorefrontVO storefrontVO : this.storefrontList) {
				storefrontName += " " + storefrontVO.getStoName();
			}
		}
		return storefrontName;
	}

	@Transient
	public String getEnabledName() {
		return DeliveryManEnum.getTextByValue(this.delEnabled);
	}
}
